package com.zhuss.core.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.zhuss.bean.bo.core.config.CreateConfigBo;
import com.zhuss.bean.bo.core.config.DecrConfigSortBo;
import com.zhuss.bean.bo.core.config.DeleteConfigBo;
import com.zhuss.bean.bo.core.config.IncrConfigSortBo;
import com.zhuss.bean.bo.core.config.UpdateConfigBo;
import com.zhuss.common.OperateService;
import com.zhuss.common.Processor;
import com.zhuss.exception.AabException;

/**
 * 配置操作service（基本操作）
 * @author zhushanshuo
 * @Date 2020-02-20 11:58
 *
 */
@Component("configOperateService")
public class ConfigOperateService implements OperateService<Void, Object> {
	
	@Autowired
	@Qualifier("configCreate")
	private Processor<Object, CreateConfigBo> configCreate;
	
	@Autowired
	@Qualifier("configUpdate")
	private Processor<Object, UpdateConfigBo> configUpdate;
	
	@Autowired
	@Qualifier("configDelete")
	private Processor<Object, DeleteConfigBo> configDelete;
	
	@Autowired
	@Qualifier("configIncrSort")
	private Processor<Object, IncrConfigSortBo> configIncrSort;
	
	@Autowired
	@Qualifier("configDecrSort")
	private Processor<Object, DecrConfigSortBo> configDecrSort;
	
	/**
	 * 创建
	 */
	@Override
    @Transactional(rollbackFor = Exception.class)
	public Void create(Object param) throws AabException {
		
		CreateConfigBo bo = (CreateConfigBo) param;
		
		configCreate.process(bo);
		
		return null;
	}
    
	/**
	 * 修改
	 */
	@Override
    @Transactional(rollbackFor = Exception.class)
    public Void update(Object param) throws AabException {
    	
		UpdateConfigBo bo = (UpdateConfigBo) param;
		
		configUpdate.process(bo);
		
    	return null;
    }
	
	/**
	 * 删除
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public Void delete(Object param) throws AabException {
		
		DeleteConfigBo bo = (DeleteConfigBo) param;
		
		configDelete.process(bo);
		
		return null;
	}
	
	/**
	 * 上移
	 * 顺序
	 */
	@Transactional(rollbackFor = Exception.class)
	public Void incrSort(Object param) throws AabException {
		
		IncrConfigSortBo bo = (IncrConfigSortBo) param;
		
		configIncrSort.process(bo);
		
		return null;
	}
	
	/**
	 * 下移
	 * 顺序
	 */
	@Transactional(rollbackFor = Exception.class)
	public Void decrSort(Object param) throws AabException {
		
		DecrConfigSortBo bo = (DecrConfigSortBo) param;
		
		configDecrSort.process(bo);
		
		return null;
	}
	
}

